package com.openspring.framework.tree;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.swing.SortOrder;

public class Node {
	
	private Long id;
	private Long customId;
	private Long parentId;
	private String text;
	private String iconCls;
	private Boolean checked;
	private List<Node> children = new ArrayList<Node>();
	private boolean expanded = false;
	private Boolean leaf;
	private long sort;

	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Long getParentId() {
		return parentId;
	}
	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
	public String getIconCls() {
		return iconCls;
	}
	public void setIconCls(String iconCls) {
		this.iconCls = iconCls;
	}
	public Boolean getChecked() {
		return checked;
	}
	public void setChecked(Boolean checked) {
		this.checked = checked;
	}
	public List<Node> getChildren() {
		return children;
	}
	public void setChildren(List<Node> children) {
		this.children = children;
	}
	public boolean isExpanded() {
		return expanded;
	}
	public void setExpanded(boolean expanded) {
		this.expanded = expanded;
	}
	public boolean isLeaf() {
		if(leaf == null)
			return children.isEmpty();
		return leaf;
	}
	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}
	public long getSort() {
		return sort;
	}
	public void setSort(long sort) {
		this.sort = sort;
	}
	
	public void sort(SortOrder order) {
		switch(order) {
			case ASCENDING : Collections.sort(children, new SortAsc()); break;
			case DESCENDING : Collections.sort(children, new SortDesc()); break;
			case UNSORTED : break;
		}
		Iterator<Node> iter = children.iterator();
		while(iter.hasNext()) {
			iter.next().sort(order);
		}
	}
	public Long getCustomId() {
		return customId;
	}
	public void setCustomId(Long customId) {
		this.customId = customId;
	}
}
